import os

page = str(open('C:/Users/Artur/Downloads/folder_submissions_users.d2l.htm').read())

names = []
start = 0

while(True):
    start = page.find('<td class="dlay_l">', start)
    if(start == -1): break
    
    start = page.find('<label>', start) + len('<label>')
    end = page.find('</label>', start)
    
    names.append(page[start:end])
    

files = []

os.chdir("C:/Users/Artur/Desktop/a3")
for f in os.listdir(): 
    (fname, ext) =  f.rsplit('.', 1)
    (name_original, rest) = fname.split(' - ', 1)
    
    name_original = set(name_original.split())
    name = {}
    for name in names:
        name_set = set(name.split())
        if(name_set == name_original): break
    
    os.rename(f, "{} - {}.{}".format(name, rest, ext))
    #os.rename(f, "{} - {}.{}".format(year, months[month], int(day), ext))